package com.meida.student.app.scholartyrant.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.mybatis.interceptor.SaveInterceptor;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaSave;
import com.meida.common.security.OpenHelper;
import com.meida.module.user.client.entity.AppEducational;
import org.springframework.stereotype.Component;

@Component("AppEducationalSaveHandler")
public class AppEducationalSaveHandler implements SaveInterceptor<AppEducational> {

    @Override
    public ResultBody validate(CriteriaSave cs, EntityMap params) {
        Long schoolId = params.getLong("schoolId");
        if (FlymeUtils.isEmpty(schoolId)) {
            return ResultBody.failed("请选择学校");
        }
        Long educationId = params.getLong("educationId");
        if (FlymeUtils.isEmpty(educationId)) {
            return ResultBody.failed("请选择学历");
        }
        String major = params.get("major");
        if (FlymeUtils.isEmpty(major)) {
            return ResultBody.failed("请填写专业");
        }
        String educationDate = params.get("educationDate");
        if (FlymeUtils.isEmpty(educationDate)) {
            return ResultBody.failed("请选择教育时间");
        }
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaSave criteriaSave, EntityMap entityMap, AppEducational appEducational) {
        Long userId = OpenHelper.getUserId();
        appEducational.setUserId(userId);
        appEducational.setState(0);
    }


}
